﻿using MediatR;
using SystemMHB.API.Application.Command.SupplierCommand;
using SystemMHB.Infrstructer.Interface;

namespace SystemMHB.API.Application.CommandHandlers.SupplierCommandHandlers
{
    public class SupplierDeleteCommandHandler:IRequestHandler<SupplierDeleteCommand,int>
    {
        /// <summary>
        /// 供应商仓储接口
        /// </summary>
        ISupplierRepository supRep;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="supRep">供应商仓储接口</param>
        public SupplierDeleteCommandHandler(ISupplierRepository supRep)
        {
            this.supRep = supRep;
        }

        public async Task<int> Handle(SupplierDeleteCommand request, CancellationToken cancellationToken)
        {
            request.DelectName = "张三";
            request.DelectTime = DateTime.Now.ToUniversalTime();
            var quotie = await supRep.GetModelAsync(request.supplierID);
            quotie.IsDel = true;
            quotie.DelectTime = request.DelectTime;
            quotie.DelectName = request.DelectName;
            return await supRep.UpdateAsync(quotie);
        }
    }
}
